package cn.com.haopy.dataes.hbase.web;


import cn.com.haopy.dataes.hbase.service.base.HBaseAdminService;
import cn.com.haopy.dataes.hbase.service.user.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.PageFilter;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/hbaseTest/")
@Slf4j
public class TestController {

    @Autowired
    StudentService studentService;
    @Autowired
    HBaseAdminService hBaseAdminService;


    @GetMapping("template")
    public Object template() {
        Map<String, Object> data = new HashMap<>();
        data.put("name", "徐亚才");
        return data;// studentService.selectList("100", "101");
    }

    @GetMapping("tables")
    public Object tables() throws IOException {
        List<String> tables = hBaseAdminService.getAllTableNames();
        return tables;
    }

    @GetMapping("createSpace")
    public Object createSpace() throws IOException {
        Boolean tables = hBaseAdminService.creatSpace("healthy");
        return tables;
    }

    @GetMapping("getData")
    public Object getData() throws Exception {
        String nameSpace = "healthy";
        String table = "h_recipel";
        Map<String, String> data = hBaseAdminService.getDataRowKey(nameSpace, table, "1169561507830525952");

        return data;

    }

    @GetMapping("getDataLimit")
    public Object getDataLimit() throws Exception {
        String nameSpace = "healthy";
        String table = "h_recipel";
        List<Map<String, String>> data = hBaseAdminService.getDataLimit(nameSpace,table,10);

        return data;

    }


    @GetMapping("getDataFilter")
    public Object getDataFilter() throws Exception {
        System.out.println(LocalDateTime.now());
        String nameSpace = "healthy";
        String table = "h_recipel";
        Filter filter = new PageFilter(10);
        List<Map<String, String>> data = hBaseAdminService.getDataFilter(nameSpace,table,filter);
        System.out.println(LocalDateTime.now());

        return data;

    }

}
